﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using MvcEngine.Mvc.Models.ViewModels;
using MvcEngine.Blog.Models.Entities;
using MvcEngine.Core;
using MvcEngine.Blog.Repositories;
using MvcEngine.Core.Utils;
using MvcEngine.Blog.Managers;

namespace MvcEngine.Blog.Filters
{
    public class BlogNameListActionFilter : IActionFilter
    {
        private IBlogRepository blogRepository = null;

        public BlogNameListActionFilter(IBlogRepository blogRepository)
        {
            this.blogRepository = blogRepository;
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {

        }

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            MvcEngineModel model = filterContext.Controller.ViewData.Model as MvcEngineModel;
            if (model == null)
                return;

            var result = new List<string>();
            foreach (var item in BlogManager.Current.GetBlogs())
            {
                result.Add(item.Name);
            }
            model.AddModelItem<IList<string>>(result);
        }
    }
}
